package completablefuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class Test3 {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        MyUtil.currentDate("执行前");
        CompletableFuture<Integer> future1 = CompletableFuture.supplyAsync(() -> {
            MyUtil.sleep(1000);
            return 1;
        });

        CompletableFuture<Integer> future2 = CompletableFuture.supplyAsync(() -> {
            MyUtil.sleep(2000);
            return 2;
        });
        CompletableFuture<Integer> future = future1.thenCombine(future2, Integer::sum);
        Integer result = future.get();
        System.out.println(result);
        MyUtil.currentDate("执行后");
    }
}
